<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:fragment="head(title)">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title th:replace="${title}">后台导航栏模板</title>
    <!--引入图标-->
    <link rel="icon" type="image/x-icon" href="../static/favicon.ico" th:href="@{/favicon.ico}"/>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
    <link rel="stylesheet" href="../../static/lib/editormd/css/editormd.min.css"
          th:href="@{/lib/editormd/css/editormd.min.css}">
    <link rel="stylesheet" href="../../static/css/me.css" th:href="@{/css/me.css}">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css">
    <script src="https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/autoload.js"></script>
</head>
<body>

<!--导航-->
<nav th:fragment="menu(n)" class="ui inverted attached segment m-padded-tb-mini m-shadow-small">
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui teal header item">管理后台</h2>
            <a href="#" th:href="@{/admin/blogs}" class=" m-item item m-mobile-hide"
               th:classappend="${n==1} ? 'active'"><i class="mini home icon"></i>博客</a>
            <a href="#" th:href="@{/admin/types}" class=" m-item item m-mobile-hide"
               th:classappend="${n==2} ? 'active'"><i class="mini idea icon"></i>分类</a>
            <a href="#" th:href="@{/admin/tags}" class="m-item item m-mobile-hide"
               th:classappend="${n==3} ? 'active'"><i class="mini tags icon"></i>标签</a>
            <a href="#" th:href="@{/}" class="m-item item m-mobile-hide"
               th:classappend="${n==4} ? 'active'"><i class="mini tags icon"></i>博客首页</a>
            <div class="right m-item m-mobile-hide menu">
                <div class="ui dropdown  item">
                    <div class="text">
                        <img class="ui avatar image" src="https://unsplash.it/100/100?image=1005"
                             th:src="@{${session.user.avatar}}">
                        <span th:text="${session.user.nickname}">洪里堃</span>
                    </div>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a href="#" class="item" onclick="aa()">个人资料</a>
                        <a href="#" th:href="@{/admin/logout}" class="item">退出登录</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
    <!---->
    <div class="ui modal" style="height: 300px">
        <form id="userform" action="/admin/updateUser" method="post" enctype="multipart/form-data">
            <input type="hidden" name="id" th:value="${session.user.id}" />
            <img id="picture" src="" width="106" alt="" th:src="@{${session.user.avatar}}"> <br />
            上传图片目录：<input type="file" name="file" id='file' onchange="showPic(this)"/><br>
            昵称：<input type="text" name="nickname" th:value="${session.user.nickname}" /><br>
            用户名：<input type="text" name="username" th:value="${session.user.username}" /><br>
            邮箱：<input type="email" name="email" th:value="${session.user.email}"/><br>
            密码：<input type="password" name="password" th:value="${session.user.password}" /><br>
            <input type="submit" value="提交编辑"/>
        </form>
    </div>
</nav>


<!--底部footer-->
<footer th:fragment="footer" class="ui inverted vertical segment m-padded-tb-massive">
    <div class="ui center aligned container">
        <div class="ui inverted divided stackable grid">
            <div class="three wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <img src="../static/images/wechat.jpg" th:src="@{/images/wechat.jpg}" class="ui rounded image"
                             alt="" style="width: 110px">
                    </div>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced ">最新博客</h4>
                <div id="newblog-container">
                    <div class="ui inverted link list" th:each="blog : ${newblogs}">
                        <a href="#" th:href="@{/blog/{id}(id=${blog.id})}" target="_blank" class="item m-text-thin"
                           th:text="${blog.title}">用户故事（User Story）</a>
                    </div>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced ">联系我</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item m-text-thin">Email：1785791276@qq.com</a>
                    <a href="#" class="item m-text-thin">QQ：1785791276</a>
                </div>
            </div>
            <div class="seven wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced ">临江仙·梦后楼台高锁</h4>
                <p class="m-text-thin m-text-spaced m-opacity-mini">
                    梦后楼台高锁，酒醒帘幕低垂。去年春恨却来时。落花人独立，微雨燕双飞。</p>
                <p class="m-text-thin m-text-spaced m-opacity-mini">
                    记得小苹初见，两重心字罗衣。琵琶弦上说相思。当时明月在，曾照彩云归。</p>
            </div>
        </div>
        <div class="ui inverted section divider"></div>
        <div style="color: #F08047;margin-top: -18px" class="ui inverted m-text-thin m-text-spaced">我的客栈已营业：<span id="htmer_time" class="item m-text-thin"></span> (*๓´╰╯`๓)</div>
        <div style="color: #F08047;margin-top: 0px" class="ui inverted m-text-thin m-text-spaced">ICP备案号：<a rel="nofollow" style="color:#F08047 " href="http://beian.miit.gov.cn" target="_blank">豫ICP备2020032250号-1</a></div>
        <div style="color: #F08047;margin-top: 0px" class="ui inverted m-text-thin m-text-spaced">公安联网备案号：<a rel="nofollow" style="color:#F08047 " href="http://www.beian.gov.cn" target="_blank">41132402411665</a></div>
    </div>


</footer>

<th:block th:fragment="script">
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
    <script src="../../static/lib/editormd/editormd.min.js" th:src="@{/lib/editormd/editormd.min.js}"></script>
    <script>
        /*function edit() {
            $.ajax({
                type:"post",
                date: FormData,
                cache:false,
                async:false,
                processData: false,
                contentType: false,
                /!*datatype: json,*!/
                url: "/admin/updateUser",
                data: {"id":id, "file":file, "nickname":nickname, "username":username, "password":password, "email":email},
                success: function (result) {
                    console.log(result)
                    if (result==ture) {
                        alert("修改成功")
                    }
                    alert("修改失败")
                }
            })

        }*/
        //图片回显+图片格式+文件类型
        function showPic(obj) {
            var newPreview = document.getElementById('picture');
            if (obj) {
                //ie浏览器兼容
                if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
                    obj.select();
                    newPreview.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);";
                    var path = document.selection.createRange().text;
                    var flag = judgeImgSuffix(path);
                    if (flag) {
                        newPreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = document.selection.createRange().text;
                    } else {
                        alert("要求图片格式为png,jpg,jpeg,bmp");
                    }

                    return;
                }
                //firefox浏览器兼容
                else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
                    if (obj.files) {
                        newPreview.src = window.URL.createObjectURL(obj.files.item(0));
                        return;
                    }
                    newPreview.src = obj.value;
                    return;
                }
                newPreview.src = obj.value;
                return;
            }
        }

        function judgeImgSuffix(path) {
            var index = path.lastIndexOf('.');
            var suffix = "";
            if (index > 0) {
                suffix = path.substring(index + 1);
            }
            if ("png" == suffix || "jpg" == suffix || "jpeg" == suffix
                || "bmp" == suffix || "PNG" == suffix || "JPG" == suffix
                || "JPEG" == suffix || "BMP" == suffix) {
                return true;
            } else {
                //alert("请上传正确到的图片格式");
                return false;
            }

        }
        function aa(){
            $('.ui.modal')
                .modal('show')
            ;
        }
        $('#newblog-container').load(/*[[@{/footer/newblog}]]*/"/footer/newblog");
        // 运行时间统计
        function secondToDate(second) {
            if (!second) {
                return 0;
            }
            var time = new Array(0, 0, 0, 0, 0);
            if (second >= 365 * 24 * 3600) {
                time[0] = parseInt(second / (365 * 24 * 3600));
                second %= 365 * 24 * 3600;
            }
            if (second >= 24 * 3600) {
                time[1] = parseInt(second / (24 * 3600));
                second %= 24 * 3600;
            }
            if (second >= 3600) {
                time[2] = parseInt(second / 3600);
                second %= 3600;
            }
            if (second >= 60) {
                time[3] = parseInt(second / 60);
                second %= 60;
            }
            if (second > 0) {
                time[4] = second;
            }
            return time;
        }
        function setTime() {
            /*此处为网站的创建时间*/
            var create_time = Math.round(new Date(Date.UTC(2020, 01, 25, 15, 15, 15)).getTime() / 1000);
            var timestamp = Math.round((new Date().getTime() + 8 * 60 * 60 * 1000) / 1000);
            currentTime = secondToDate((timestamp - create_time));
            currentTimeHtml = currentTime[0] + '年' + currentTime[1] + '天'
                + currentTime[2] + '时' + currentTime[3] + '分' + currentTime[4]
                + '秒';
            document.getElementById("htmer_time").innerHTML = currentTimeHtml;
        }
        setInterval(setTime, 1000);
    </script>
</th:block>

</body>
</html>